package dongtai;

public class siliuqi {
    public static int findSubstringInWraproundString(String s) {
        int n=s.length();
        if(n==1){
            return 1;
        }
        //将字符串数组转化为字符数组
        char[] charArray=s.toCharArray();
        //获取字符数组的ascii值
        int[] asciiArray=new int[charArray.length];
        for(int i=0;i<charArray.length;i++){
            asciiArray[i]=(int)charArray[i];
        }
        int[] f=new int[n];
        for(int i=0;i<f.length;i++){
            f[i]=1;
        }
        int[] maxLen=new int[26];
        //先处理第一个字符
        maxLen[charArray[0]-'a']=1;
        //将f全部初始化为1
//        for(int m:f){
//            m=1;
//        }
        for(int i=1;i<n;i++){
            if((charArray[i-1]=='z'&&charArray[i]=='a')||
                    asciiArray[i-1]+1==asciiArray[i]){
                f[i]=f[i-1]+1;
            }
            if(maxLen[charArray[i]-'a']<f[i]){
                maxLen[charArray[i]-'a']=f[i];
            }

        }
        int sum=0;
        for(int max:maxLen){
            sum+=max;
        }
        return sum;
    }

    public static void main(String[] args) {
        String s="cac";
        int substringInWraproundString = findSubstringInWraproundString(s);
        System.out.println(substringInWraproundString);

    }
}
